package com.example.calculateshopprice.fruitshop;

import com.example.calculateshopprice.fruit.Fruit;

import java.security.Key;
import java.util.HashMap;
import java.util.Map;

public class CalFruitsPriceTotals {
//    private Fruit apple;
//    private Fruit strawberry;
//    private Fruit mango;
//
//    public CalFruitsPriceTotals(Fruit apple, Fruit strawberry, Fruit mango) {
//        this.apple = apple;
//        this.strawberry = strawberry;
//        this.mango = mango;
//    }
    private Map<Fruit, Integer> items;

    public CalFruitsPriceTotals() {

        items = new HashMap<>();
    }

    public void addFruit(Fruit fruit, int quantity) {
        if (items.containsKey(fruit)) {
            quantity += items.get(fruit);
        }
        items.put(fruit, quantity);
    }

    public double calculateTotalPrice() {
        double totalPrice = 0;
        for (Map.Entry<Fruit, Integer> s : items.entrySet()) {
            Fruit fruit = s.getKey();
            int quantity = s.getValue();
           System.out.println(items);
            System.out.println(fruit.getName());

//           double dd= items.get(fruit).doubleValue();
//            System.out.println(dd);


//            if (items.equals("strawberry")) {
//           double  sdd=fruit.getPrice();
//               sdd *= 0.8; // 如果是草莓，打八折
//            }
            // 促销活动：草莓打 8 折
//            dd *= (strawberry.getName().equals("草莓") ? 0.8 : 1);
            totalPrice += fruit.getPrice() * quantity;
        }
        return totalPrice;
    }


}

